<%@ page import="com.wuming.caiwu.security.SecurityHander" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>查看订单详情</title>
    <link rel="stylesheet" href="${allServerPath}static/layui/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${allServerPath}static/layui/css/public.css" media="all"/>
    <!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">-->
    <!--<link rel="stylesheet" href="bootstrap-select-master/dist/css/bootstrap-select.css">-->
    <script type="text/javascript" src="${allServerPath}static/layui/layui/layui.js"></script>
</head>
<body style="background-color: #f0f2f5;" class="childrenBody">
<div class="layui-fluid wuli-main">
    <div class="layui-row">
        <fieldset class="layui-elem-field layui-field-title">
            <legend>订单详情</legend>
        </fieldset>

        <blockquote class="layui-elem-quote">订单基本信息</blockquote>

        <div class="layui-row">
            <div class="layui-col-md4">
                <div class="grid-demo grid-demo-bg1">
                    <label class="layui-form-label">订单编号:</label>
                    <div class="layui-form-label">
                        ${order.orderSn}
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="grid-demo">
                    <label class="layui-form-label">订单时间:</label>
                    <div class="layui-form-label" style="width: 200px;">
                        <fmt:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="grid-demo grid-demo-bg1">
                    <label class="layui-form-label">会员昵称:</label>
                    <div class="layui-form-label">
                        ${order.memberUsername}
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-md4">
                <div class="grid-demo grid-demo-bg1">
                    <label class="layui-form-label">收货人:</label>
                    <div class="layui-form-label">
                        ${order.receiverName}
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="grid-demo">
                    <label class="layui-form-label">订单金额:</label>
                    <div class="layui-form-label" style="width: 200px;">
                        ${order.payAmount}
                    </div>
                </div>
            </div>
            <div class="layui-col-md4">
                <div class="grid-demo grid-demo-bg1">
                    <label class="layui-form-label">订单状态:</label>
                    <c:if test="${order.status == 0 || order.status == 12}">
                        <div class="layui-form-label">
                            未支付
                        </div>
                    </c:if>
                    <c:if test="${order.status == 1}">
                        <div class="layui-form-label">
                            已付款
                        </div>
                    </c:if>
                    <c:if test="${order.status == 2}">
                        <div class="layui-form-label">
                            已通知取货
                        </div>
                    </c:if>
                    <c:if test="${order.status == 3}">
                        <div class="layui-form-label">
                            已取货
                        </div>
                    </c:if>
                    <c:if test="${order.status == 4}">
                        <div class="layui-form-label">
                            已完成
                        </div>
                    </c:if>
                </div>
            </div>
        </div>

        <blockquote class="layui-elem-quote">商品基本信息</blockquote>
        <button id="btnExport" class="layui-btn layui-btn-normal" data-type="reload">导出信息</button>
        <table class="layui-hide" id="orderItemInfo" lay-filter="orderItem" lay-data="{height: 'full-200'}">
        </table>
    </div>
</div>
</div>

<script type="text/html" id="barDemo">
<shiro:hasAnyRoles
        name="factory:manage">
    <%--<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="sendgoodset">发货设置</a>--%>
</shiro:hasAnyRoles>
</script>

<script>
    layui.use(['layer', 'table', 'laydate', 'jquery'], function () {
        var table = layui.table
            , layer = layui.layer
            , $ = layui.$;

        $("#btnExport").click(function () {
            $.ajax({
                    url: '${allServerPath}web/order/exportInfo.htmls',
                    method: 'get',
                    dataType: 'json',
                    data:{
                        "orderId": '${order.id}'
                    },
                    success: function (result) {
                        if (result.success) {
                            layer.msg('导出成功.');
                            FileUtil.downFile("${allServerPath}/web/base/downLoadTempFile.htmls", result.data);
                        }
                    },
                    error: function () {
                        layer.msg('删除失败,请稍后重试.');
                    }
                }
            );
        });

        var type = '${type}';
        var whereParam = {};
        if(type == "0"){
            whereParam['supplyId'] = '<%=SecurityHander.getCurrentUserId()%>';
            whereParam['orderId'] = '${order.id}';
        }else if(type == "1"){
            whereParam['storeId'] = '<%=SecurityHander.getCurrentUserId()%>';
            whereParam['orderId'] = '${order.id}';
        }


        table.render({ //其它参数在此省略
            elem: '#orderItemInfo'
//            , height: 500
            , url: '${allServerPath}web/order/getOrderItemById.htmls?t=' + Date.parse(new Date())
            , cols: [[ //表头
                {field: 'id', width: 80, title: '序号', align: 'center', fixed: 'left'}
                , {field: 'productName', title: '商品名称', align: 'center', width: 200}
                , {field: 'productBrand', title: '商品品牌', align: 'center', width: 200}
                , {field: 'productPrice', title: '商品价格', align: 'center', width: 200}
                , {field: 'productQuantity', title: '商品数量', align: 'center'}
                , {fixed: 'right', title: '操作', align: 'center', templet: '#barDemo'}
            ]],
            id: 'orderItemContent',
            where: whereParam, //如果无需传递额外参数，可不加该参数
            method: 'get', //如果无需自定义HTTP类型，可不加该参数
            page: true,
            limits: [10, 20, 30, 50, 100, 200],
            limit: 10,
            request: {
                pageName: 'pageIndex', //页码的参数名称，默认：page
                limitName: 'pageSize'
            }, //如果无需自定义请求参数，可不加该参数
            response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , statusCode: 200 //成功的状态码，默认：0
                , msgName: 'message' //状态信息的字段名称，默认：msg
                , countName: 'total' //数据总数的字段名称，默认：count
                , dataName: 'data' //数据列表的字段名称，默认：data
            }, //如果无需自定义数据响应名称，可不加该参数
            done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                console.log(res);

                //得到当前页码
                console.log(curr);

                //得到数据总量
                console.log(count);
            },
            text: {
                none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }
        });

        table.on('tool(orderItem)', function (obj) {
            var data = obj.data;
            if (obj.event === 'sendgoodset') {
                layer.open({
                    type: 2,
                    title: '发货设置',
                    maxmin: true,
                    shadeClose: true, //点击遮罩关闭层
                    area: ['1000px', '580px'],
                    content: '${allServerPath}web/sendgoodset/editSendgoodsSet/' + data.id + '.htmls'
                });
            }
        });

        var FileUtil = {
            downFile: function (url, data) {
                if (url && data) {
                    var inputs = '';
                    for (var p in data) {
                        inputs += '<input type="hidden" name="' + p + '" value="' + data[p]
                            + '" />';
                    }
                    $('<form action="' + url + '" method="post">' + inputs + '</form>')
                        .appendTo('body').submit().remove();
                }
            }
        }
    });


</script>
</body>
</html>
